﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GcmpGeometryInterface.h"

namespace gcmp
{
    class Box2d;
    class Box3d;

    /// \brief 包围盒的rtree树,支持二维包围盒及三维包围盒
    template<typename T>
    class GCMP_GEOMETRY_INTERFACE_EXPORT BoxRTree
    {
    public:
        /// \brief  析构函数
        virtual ~BoxRTree() {};
    public:  
        /// \brief  rtree树中插入数据
        /// \param box     包围盒
        /// \param dataId   数据id
        /// \return   void
        virtual void Insert(const T& box, Int64 dataId) = 0;

        /// \brief  rtree树中移除数据
        /// \param box     包围盒
        /// \param dataId   数据id
        /// \return   void
        virtual void Remove(const T& box, Int64 dataId) = 0;

        /// \brief  rtree树中更新数据
        /// \param box     原始旧的包围盒
        /// \param dataId   数据id
        /// \param newBox    新的包围盒
        /// \return   void
        virtual void Update(const T& box, Int64 dataId, const T& newBox) = 0;

        /// \brief  给定包围盒查询与包围盒相交的数据集合
        /// \param box     包围盒
        /// \param dataId  返回搜索到数据id几何
        /// \return   返回搜索的数量
        virtual int Search(const T& box, std::vector<Int64>& dataIds) = 0;

        /// \brief  rtree树中移除所有
        /// \return   void
        virtual void RemoveAll() = 0;      
     };

    /// \brief  只支持Box2d和Box3d
    template class BoxRTree<Box2d>;
    template class BoxRTree<Box3d>;


    /// \brief 创建包围盒的rtree树的工具类
    class GCMP_GEOMETRY_INTERFACE_EXPORT BoxRTreeUtils
    {
    public:
        /// \brief  创建3维的包围盒rtree树
        /// \param dist     容差
        /// \return   3维的包围盒rtree树
        static OwnerPtr<BoxRTree<Box3d>> CreateBox3dRTree(double dist);

        // \brief  创建2维的包围盒rtree树
        /// \param dist     容差
        /// \return  2维的包围盒rtree树
        static OwnerPtr<BoxRTree<Box2d>> CreateBox2dRTree(double dist);
    };
}


